home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 265 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.2 KB  |  63 lines

  1. Newsgroups: comp.lang.c,comp.lang.c++
  2. Path: bath.ac.uk!bsmail!talisker!nathan
  3. From: nathan@pact.srf.ac.uk (Nathan Sidwell)
  4. Subject: Re: Poor floating point code in BC++
  5. Message-ID: <DKLtwv.MME@uns.bris.ac.uk>
  6. Followup-To: comp.lang.c,comp.lang.c++
  7. Sender: usenet@uns.bris.ac.uk (Usenet news owner)
  8. Nntp-Posting-Host: talisker.pact.srf.ac.uk
  9. Organization: Inmos
  10. X-Newsreader: TIN [version 1.2 PL2]
  11. References: <4c9sja$gke$1@mhafc.production.compuserve.com>
  12. Date: Wed, 3 Jan 1996 12:12:30 GMT
  13.  
  14. Dave Hand (70621.3624@CompuServe.COM) wrote:
  15. : BC++ 4.51 seems to generate very poor floating point code. I would be
  16. : interested to know how well other compilers do on the following
  17. : examples. These were compiled using options: i486 CPU, fast floating
  18. : point, optimize for speed, large memory model.
  19.  
  20. :[float to int conversion]
  21.  
  22. : where FTOL@ is a very long function for what is does:
  23.  
  24. :     push bp
  25. :     mov bp,sp
  26. :     sub sp,000A
  27. :     fnstcw word ptr[bp-02]
  28. :     fwait
  29. :     mov al,[bp-01]
  30. :     or byte ptr[bp-01],0C
  31. :     fldcw word ptr[bp-02]
  32. :     fistp qword ptr [bp-0A]  <<-- here is the meat of it.
  33. :     mov [bp-01],al
  34. :     fldcw word ptr[bp-02]
  35. :     mov ax,[bp-0A]
  36. :     mov dx,[bp-08]
  37. :     mov sp,bp
  38. :     pop bp
  39. :     retf
  40.  
  41. The preamble is saving the rounding mode and setting it to round to zero
  42. (I think, I've not got a 387 manual infront of me) and the postamble
  43. is restoring the previous rounding mode.
  44.  
  45. It has to be done this way, because
  46. a)float to int conversion is defined to remove the 'fractional part'. On
  47. a sign magnitude system (which 387 is), this is the same as round to zero.
  48. b)there is a function to set the rounding mode for all operations (I forget
  49. the name), thus the rounding mode is unknown and must be preserved by the
  50. conversion.
  51.  
  52. Unfortuneately the compiler cannot tell when the rounding mode is already
  53. correct, it's a problem with the 387 instruction set not having instructions
  54. which explicitly state the rounding mode to use.
  55.  
  56. nathan
  57. --
  58. Nathan Sidwell                         Holder of the Xmris home page
  59. Chameleon Architecture Group at SGS-Thomson, formerly Inmos
  60. http://www.pact.srf.ac.uk/~nathan/                  Tel 0117 9707182
  61. nathan@inmos.co.uk or nathan@bristol.st.com or nathan@pact.srf.ac.uk
  62. Having problems?     try http://www.pact.srf.ac.uk/~nathan/problems/
  63.